<template>
  <el-card class="app-container">
    <c-u-r-d-table :option="option"/>
  </el-card>
</template>

<script>

import ColumnType from '@/framework/constant/ColumnType'
import OnlineStatusEnum from '@/framework/constant/OnlineStatusEnum'
import { merchantApi } from '@/feature/mms/infra/api/merchantApi'
import CURDTable from '@/framework/components/table/CURDTable'
import { roleApi } from '@/feature/mms/infra/api/roleApi'

export default {
  components: { CURDTable },
  data() {
    return {
      option: {
        dialogWidth: '600px',
        loadDetail: true,
        requestApi: merchantApi,
        columns: [
          {
            label: '商户名称',
            searchable: true,
            width: 'auto',
            span: 24,
            required: true,
            prop: 'title'
          },
          {
            label: 'AppID',
            width: 180,
            hiddenInForm: true,
            prop: 'appId'
          },
          {
            label: '登录账号',
            required: true,
            span: 24,
            prop: 'loginName'
          }, {
            label: '角色',
            required: true,
            span: 24,
            hiddenInTable: true,
            type: ColumnType.SELECT,
            options: roleApi.listAll(),
            renderOptions: { multiple: true },
            prop: 'roleIdList'
          },
          {
            label: '最近登录时间',
            hiddenInForm: true,
            prop: 'lastLoginTime'
          },
          {
            label: '最近登录IP',
            hiddenInForm: true,
            prop: 'lastLoginIp'
          },
          {
            label: '状态',
            searchable: true,
            type: ColumnType.RADIO,
            hiddenInForm: true,
            options: OnlineStatusEnum,
            prop: 'status'
          },
          {
            label: '创建时间',
            type: ColumnType.DATETIME,
            hiddenInForm: true,
            prop: 'gmtCreate'
          },
          {
            label: '修改时间',
            type: ColumnType.DATETIME,
            hiddenInForm: true,
            prop: 'gmtModified'
          }
        ]
      }
    }
  },
  methods: {
    async handleResetPassword({ arg: { id } }) {
      await this.$confirm('确认重置密码吗？', '提示')
      const newPwd = await merchantApi.resetPassword(id)
      await this.$alert('重置密码成功，请使用新密码：' + newPwd, '提示')
    },
    async onAddSuccess(data) {
      await this.$alert('创建商户成功，密码：' + data, '提示')
    }
  }
}
</script>

